﻿<UserControl x:Class="TheMovieDb.Example.Views.MoviesView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:vm="clr-namespace:TheMovieDb.Example.ViewModels"
             xmlns:code="clr-namespace:TheMovieDb.Example.Converters" mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.DataContext>
        <vm:MoviesViewModel />
    </UserControl.DataContext>
    <UserControl.Resources>
        <code:ThumbnailConverter x:Key="thumbnailConverter" />
        <code:TextConverter x:Key="textConverter" />
        <code:CastMemberConverter x:Key="castMemberConverter" />
        <code:TmdbImageConverter x:Key="tmdbImageConverter" />
    </UserControl.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="300" />
            <ColumnDefinition Width="3" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>

            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <TextBox Text="{Binding SearchText, Mode=TwoWay}" Margin="3" />
                <Button Grid.Column="1" Content="Search" Command="{Binding SearchCommand}" Margin="3" />
            </Grid>
            <ListBox Grid.Row="1" ItemsSource="{Binding Movies}" SelectedItem="{Binding SelectedMovie, Mode=TwoWay}" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="*" />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>

                            <Image Source="{Binding Posters,Converter={StaticResource thumbnailConverter},ConverterParameter='poster'}" Grid.RowSpan="2" Margin="3" VerticalAlignment="Top" Width="92" />

                            <TextBlock Margin="3" Grid.Column="1" Grid.Row="0" Text="{Binding Name}" FontWeight="Bold" TextWrapping="Wrap" />
                            <TextBlock Margin="5,3,3,3" Grid.Column="1" Grid.Row="1" TextWrapping="Wrap" Text="{Binding Overview,Converter={StaticResource textConverter}}" VerticalAlignment="Top" />


                        </Grid>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </Grid>

        <GridSplitter Grid.Column="1" Height="Auto" Width="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"  />

        <ScrollViewer Grid.Column="2" HorizontalScrollBarVisibility="Disabled">
            <Grid DataContext="{Binding Movie}" Margin="10">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>

                <TextBlock Grid.Column="0" Grid.Row="0" Text="Name:" FontWeight="Bold" Margin="3" />
                <TextBlock Grid.Column="1" Grid.Row="0" Text="{Binding Name}" Margin="3" />

                <TextBlock Grid.Column="0" Grid.Row="1" Text="Alternative Name:" FontWeight="Bold" Margin="3" />
                <TextBlock Grid.Column="1" Grid.Row="1" Text="{Binding AlternativeName}" Margin="3" />

                <TextBlock Grid.Column="0" Grid.Row="2" Text="ID:" FontWeight="Bold" Margin="3" />
                <TextBlock Grid.Column="1" Grid.Row="2" Text="{Binding Id}" Margin="3" />

                <TextBlock Grid.Column="0" Grid.Row="3" Text="Type:" FontWeight="Bold" Margin="3" />
                <TextBlock Grid.Column="1" Grid.Row="3" Text="{Binding Type}" Margin="3" />

                <TextBlock Grid.Column="0" Grid.Row="4" Text="IMDB ID:" FontWeight="Bold" Margin="3" />
                <TextBlock Grid.Column="1" Grid.Row="4" Text="{Binding ImdbId}" Margin="3" />

                <TextBlock Grid.Column="0" Grid.Row="5" Text="Url:" FontWeight="Bold" Margin="3" />
                
                <TextBlock Grid.Column="1" Grid.Row="5" Text="{Binding Url}" Margin="3" Tag="{Binding Url}" TextDecorations="Underline" Foreground="Blue" Cursor="Hand" MouseLeftButtonUp="TextBlockMouseLeftButtonUp" />

                <TextBlock Grid.Column="0" Grid.Row="6" Text="Rating:" FontWeight="Bold" Margin="3" />
                <TextBlock Grid.Column="1" Grid.Row="6" Text="{Binding Rating}" Margin="3" />

                <TextBlock Grid.Column="0" Grid.Row="7" Text="Certification:" FontWeight="Bold" Margin="3" />
                <TextBlock Grid.Column="1" Grid.Row="7" Text="{Binding Certification}" Margin="3" />

                <TextBlock Grid.Column="0" Grid.Row="8" Text="Released:" FontWeight="Bold" Margin="3" />
                <TextBlock Grid.Column="1" Grid.Row="8" Text="{Binding Released,StringFormat=d}" Margin="3" />

                <TextBlock Grid.Column="0" Grid.Row="9" Text="Budget:" FontWeight="Bold" Margin="3" />
                <TextBlock Grid.Column="1" Grid.Row="9" Text="{Binding Budget,StringFormat=c}" Margin="3" />

                <TextBlock Grid.Column="0" Grid.Row="10" Text="Revenue:" FontWeight="Bold" Margin="3" />
                <TextBlock Grid.Column="1" Grid.Row="10" Text="{Binding Revenue,StringFormat=c}" Margin="3" />

                <TextBlock Grid.Column="0" Grid.Row="11" Text="Homepage:" FontWeight="Bold" Margin="3" />
                <TextBlock Grid.Column="1" Grid.Row="11" Text="{Binding Homepage}" Margin="3" Tag="{Binding Homepage}" TextDecorations="Underline" Foreground="Blue" Cursor="Hand" MouseLeftButtonUp="TextBlockMouseLeftButtonUp" />

                <TextBlock Grid.Column="0" Grid.Row="12" Text="Trailer:" FontWeight="Bold" Margin="3" />
                <TextBlock Grid.Column="1" Grid.Row="12" Text="{Binding Trailer}" Margin="3" Tag="{Binding Trailer}" TextDecorations="Underline" Foreground="Blue" Cursor="Hand" MouseLeftButtonUp="TextBlockMouseLeftButtonUp" />

                <TextBlock Grid.Column="0" Grid.Row="13" Text="Overview:" FontWeight="Bold" Margin="3" />
                <TextBlock Grid.Column="1" Grid.Row="13" Text="{Binding Overview}" Margin="3" TextWrapping="Wrap" />

                
                <TextBlock Grid.Column="0" Grid.Row="15" Text="Studio:" FontWeight="Bold" Margin="3" />
                <ItemsControl Grid.Column="1" Grid.Row="15" ItemsSource="{Binding Studios}" Margin="3">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Name}" />
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>

                <TextBlock Grid.Column="0" Grid.Row="16" Text="Countries:" FontWeight="Bold" Margin="3" />
                <ItemsControl Grid.Column="1" Grid.Row="16" ItemsSource="{Binding Countries}" Margin="3">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Name}" />
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>

                <TextBlock Grid.Column="0" Grid.Row="17" Text="Cast:" FontWeight="Bold" Margin="3" />
                <ItemsControl Grid.Column="1" Grid.Row="17" ItemsSource="{Binding Cast}" Margin="3">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Mode=OneWay,Converter={StaticResource castMemberConverter}}" />
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>

                <TextBlock Grid.Column="0" Grid.Row="18" Text="Posters:" FontWeight="Bold" Margin="3" />
                <ItemsControl Grid.Column="1" Grid.Row="18" ItemsSource="{Binding Posters,Converter={StaticResource tmdbImageConverter},ConverterParameter='poster'}" Margin="3">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <Image Source="{Binding ImageInfo.Url}" Margin="5" HorizontalAlignment="Stretch" />
                            </StackPanel>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>

                <TextBlock Grid.Column="0" Grid.Row="19" Text="Backdrops:" FontWeight="Bold" Margin="3" />
                <ItemsControl Grid.Column="1" Grid.Row="19" ItemsSource="{Binding Backdrops,Converter={StaticResource tmdbImageConverter},ConverterParameter='backdrop'}" Margin="3">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <Image Source="{Binding ImageInfo.Url}" Margin="5" HorizontalAlignment="Stretch" />
                            </StackPanel>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </Grid>
        </ScrollViewer>
    </Grid>
</UserControl>
